package com.blockmeta.bbs.activity;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.blockmeta.bbs.R;
import com.blockmeta.bbs.businesslibrary.arouter.RouterPath;
import com.blockmeta.bbs.businesslibrary.base.BaseActivity;
import com.blockmeta.bbs.businesslibrary.constant.Constant;
import com.blockmeta.bbs.businesslibrary.umeng.MEDIA_TYPE;
import com.blockmeta.bbs.businesslibrary.umeng.OnShareClickListener;
import com.blockmeta.bbs.businesslibrary.umeng.ShareRouter;
import com.blockmeta.bbs.businesslibrary.umeng.ShareType;
import com.blockmeta.bbs.businesslibrary.umeng.dialog.BlockMessageShareData;
import com.blockmeta.bbs.immodule.R2;
import com.blockmeta.bbs.immodule.widget.LengthLimitEditText;
import com.umeng.socialize.UMShareAPI;

import java.util.Map;

import butterknife.BindView;


//分享页面采用flutter打开一个原生页面，可进行编辑然后分享，避免在flutter页面调用原生popwindow的麻烦
@Route(path = RouterPath.MAIN_SHARE_ACTIVITY)
public class ShareActivity extends BaseActivity {
//    @Autowired(name = Constant.ZERO)
//    public String mTitle;
//    @Autowired(name = Constant.ONE)
//    public String mContent;
//    @Autowired(name = Constant.TWO)
//    public String mShareUrl;
//    @Autowired(name = Constant.THREE)
//    public String mPic;
//    @Autowired(name = Constant.Four)
//    public Integer mId;

//    private ShareRouter mShareRouter;
    @BindView(R2.id.edt_circle_notice)
    LengthLimitEditText mEdtCircleNotice;
    @Override
    protected boolean showTitle() {
        return false;
    }


    @Override
    public View setView() {
        return LayoutInflater.from(mContext).inflate(R.layout.activity_share, null);
    }


    @Override
    protected void initialize() {
        super.initialize();

        try {
            Map<String, Object> data = (Map<String, Object>) getIntent().getSerializableExtra("NAVIGATION_ROUTE_SETTINGS");
            if (data != null && data.containsKey("params")) {
                Map<String, String> params = (Map<String, String>)data.get("params");
                BlockMessageShareData shareData = new BlockMessageShareData();
                shareData.mTitle = params.get("title");
                shareData.mPostTime = params.get("time");
                shareData.mImage = params.get("image");
                shareData.mSourceImage = params.get("image");
                shareData.mSourceName = params.get("title");
                String url = "https://www.8btc.com/article/" + params.get("id");
                shareData.mContent = params.get("content");
                new ShareRouter.Builder()
                        .context(mContext)
                        .shareType(ShareType.BLOCk_MESSAGE)
                        .url(url)
                        .thumb(shareData.mImage)
                        .describe(shareData.mContent)
                        .title(shareData.mTitle)
                        .onShareClickListener(new OnShareClickListener() {
                            @Override
                            public void onShareClickListener(MEDIA_TYPE mediaType) {
                                finish();
                            }
                        })
                        .blockMessageShareData(shareData)
                        .build()
                        .show();
            }
            } catch(Exception e){
                e.printStackTrace();
            }
        }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }


    private void setShare(String url) {
//        mShareUrl = url.replace("btc8share://", "http://");
//        Uri shareUri = Uri.parse(Uri.decode(mShareUrl));
//        String title = shareUri.getQueryParameter("title");
//        String desc = shareUri.getQueryParameter("desc");
//        if (mShareRouter == null){
//            mShareRouter = new ShareRouter.Builder()
//                    .context(mContext)
//                    .shareType(ShareType.NORMAL_WEB)
//                    .typeDescribe(TypeDescribe.ACTIVITY)
//                    .url(mShareUrl)
//                    .title(TextUtils.isEmpty(title)?sContactUSPOJO.getActivitydesc().getTitle():title)
//                    .describe(TextUtils.isEmpty(desc)?sContactUSPOJO.getActivitydesc().getDesc():desc)
//                    .umShareListener(mUMShareListener)
//                    .build();
//        }
//        mShareRouter.show();
    }
}
